﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using System.Web.Security;
using BIPorter.Common.BLL;
using BIPorter.Common.Model;

namespace BIPorter.Site.Controllers
{
    public class AccountController : Controller
    {
       AccountBll AccountBll = null;
        public AccountController()
        {
            if (AccountBll == null)
            {
                AccountBll = new AccountBll();
            }
        }

        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <param name="RememberMe"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Login(string UserName, string Password, bool RememberMe = false)
        {
            if (ModelState.IsValid)
            {
                var res = AccountBll.Login(UserName, Password, RememberMe);
                if (res.Result)
                {
                    return RedirectToAction("Default", "Home");
                }
                else
                {
                    ModelState.AddModelError("",res.Exception); 
                }
            }
            return View();
        }

        /// <summary>
        /// 注销
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginOut()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Login", "Account");
        }

    }
}
